package com.handpay.framework.swiper;

import android.content.Context;

import com.handpay.framework.swiper.landi.LandiSwiperBT;
import com.handpay.framework.swiper.landi.LandiSwiperM18;
import com.handpay.framework.swiper.landi.LandiSwiperM36;

/**
 * 创建不同实现的ApiSwiper
 *
 * @author jmshuai
 */
public class ApiSwiperFactory {

    private static IApiSwiper APISWIPER = new ApiSwiperImplement();

    // public static ZhijiaIC zhiJIaIc = null;
    public static IApiSwiper getInstance() {
        return APISWIPER;
    }

    /**
     * 初始化刷卡器
     *
     * @param c
     * @param type     刷卡器类型，0表示音频，1表示格尔蓝牙，2，表示新大陆蓝牙。具体参照R.array.swipe_types
     *                 务必和描述表示一致。
     * @param addition 当type为1的时候，addition表示mac地址
     * @return 初始化的结果。true表示成功，false表示失败。
     */
    public static boolean init(Context c, SwiperModel type, String addition) {
        if (null != APISWIPER) {
            APISWIPER.clearSwiper(null);
            IBusinessSwiper ib = null;
            switch (type) {
                case KOAL_VOICE: {
                    // 没有用到。暂时删除。包括库
                    // ib = new KoalscSwiper(c.getApplicationContext());
                    break;
                }
                case KOAL_BLUETOOTH: {
                    // 没有用到。暂时删除。包括库
                    // ib = new KoalscSwiperBT(c.getApplicationContext(), addition);
                    break;
                }
                case NEWLAND_BLUETOOTH: {
                    ib = new NewlandSwiperBT(c.getApplicationContext(), addition);
                    break;
                }
                case GJACK_VOICE_MAG: {
                    ib = new BusinessSwiper(new GjackSwiper(c.getApplicationContext(), APISWIPER));
                    break;
                }
                case GJACK_VOICE_IC: {
                    // TODO 智嘉IC需要重构，如果需要支持的话。
                    // 没有用到。暂时删除。包括库
                    // if (zhiJIaIc == null) {
                    // zhiJIaIc = new ZhijiaIC(c, addition);
                    // }
                    // ib = zhiJIaIc;
                    break;
                }
                case BBPOS_VOICE: {
                    ib = new BusinessSwiper(new BbposVoiceSwiper(c.getApplicationContext(), APISWIPER));
                    break;
                }
                case NEWLAND_VOICE_IC: {
                    ib = new BusinessSwiper(new NewlandSwiperME11(c.getApplicationContext(), addition));
                    break;
                }
                case M35_BLUETOOTH:
                    ib = new LandiSwiperBT(c.getApplicationContext(), addition);
                    break;
                case M18_BLUETOOTH:
                    ib = new BusinessSwiper(new LandiSwiperM18(c.getApplicationContext(), addition));
                    break;
                case M36_BLUETOOTH:
                    ib = new LandiSwiperM36(c.getApplicationContext(), addition);
                    break;
                case ME31_BLUETOOTH:
                    ib = new NewlandSwiperME31(c.getApplicationContext(), addition);
                    break;
                case ME368_BLUETOOTH:
                    ib = new BbposM368(c.getApplicationContext(), addition, APISWIPER);
                    break;
                case ME15_BLUETOOTH:
                    ib = new BusinessSwiper(new NewlandSwiperME15(c.getApplicationContext(), addition, APISWIPER));
                    break;

                case CMSET_VOICE:
                    ib = new BusinessSwiper(new CMSETSwiper(c.getApplicationContext(), APISWIPER));
                    break;
                case M188_BLUETOOTH:
                    ib = new BusinessSwiper(new BbposM188(c.getApplicationContext(), addition, APISWIPER));
                    break;
                case M1218_BLUETOOTH:
                    ib = new BusinessSwiper(new BbposM188(c.getApplicationContext(), addition, APISWIPER));
                    break;
                case I21B_BLUETOOTH:
                    ib = new BusinessSwiper(new ItronI21BSwiper(c.getApplicationContext(), addition, APISWIPER));
                    break;
                case P27_BLUETOOTH:
                    ib = new BusinessSwiper(new DynamiCodeP27(c.getApplicationContext(), addition, APISWIPER));
                    break;
                case M198_BLUETOOTH:
                    // 和188用同样的sdk
                    ib = new BusinessSwiper(new BbposM188(c.getApplicationContext(), addition, APISWIPER));
                    break;
                case P84_BLUETOOTH:
                    ib = new DynamiCodeP84(c.getApplicationContext(), addition, APISWIPER);
                    break;
            }
            if (ib.isSwiperReady()) {
                APISWIPER.setSwiper(ib);
                return true;
            } else {
                return false;
            }
        }
        // should never go here！
        return false;
    }
}
